package com.ruoyi.sms.controller;


import com.ruoyi.bizsys.domain.SmsTask;

import com.ruoyi.bizsys.service.ISmsTaskService;
import com.ruoyi.sms.service.ISmsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @desc 短信发送controller
 * @author pgc
 * @date 2021-10-27 10:55
 */
@Slf4j
@RestController
@CrossOrigin
@RequestMapping("/cssms")
public class SmsSendController {

    @Autowired
    private ISmsService iSmsService;


    @Autowired
    private ISmsTaskService smsTaskService;


    /**
     * 执行短信发送
     */
    @GetMapping("/sendSms")
    @Log(title = "执行短信发送", businessType = BusinessType.SMS)
    public AjaxResult sendSms() {
        //查询未发送过信息的记录
        List<SmsTask> smsTasks = smsTaskService.selectSmsTask();
        //调用短信接口发送短信
        log.info("本次执行有"+smsTasks.size()+"条");
        iSmsService.sendBatchSms(smsTasks);
        return AjaxResult.success("发送成功");
    }

}
